import Vue from 'vue'
import Vuex from 'vuex'
// 引入方法
import { setStorage, getStorage, removeStorage } from '@/Utils/storage.js'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    user: getStorage('hkzf-user'),
    cityInfo: getStorage('hkzf-city') || {
      name: '上海',
      id: 'AREA|dbf46d32-7e76-1196'
    }
  },
  mutations: {
    // 获取token
    initUser (state, payload) {
      state.user = payload
      setStorage('hkzf-user', payload)
    },
    // 删除token
    removeUser (state) {
      state.user = null
      removeStorage('hkzf-user')
    },
    // 获得当前城市地址
    getCityInfo (state, payload) {
      state.cityInfo = payload
      setStorage('hkzf-city', payload)
    }
  },
  actions: {
  },
  modules: {
  }
})
